package com.swak.telnet.function;

import com.swak.telnet.cmd.CmdInvoker;
import com.swak.telnet.cmd.Command;

/**
 * 方法级别的处理器
 * 
 * @author lifeng
 */
public class CmdFunction implements HandlerFunction {

	final CmdInvoker invoker;

	CmdFunction(CmdInvoker invoker) {
		this.invoker = invoker;
	}

	@Override
	public Object handle(Command request) {
		return invoker.doInvoke(request);
	}

	public static RouterFunction of(CmdInvoker invoker) {
		CmdFunction methodFunction = new CmdFunction(invoker);
		return RouterFunctions.cmd(invoker.getCommand(), methodFunction);
	}
}
